//
//  YYSearchResultController.m
//  YYWeather
//
//  Created by 姚英 on 16/8/28.
//  Copyright © 2016年 yy. All rights reserved.
//

#import "YYSearchResultController.h"
#import "SQLOperation.h"

@implementation YYSearchResultController


- (void)viewDidLoad {
    
    [super viewDidLoad];
    
    [self.tableView registerClass:[UITableViewCell class] forCellReuseIdentifier:@"ResultID"];
    
//    _dataSource = [NSMutableArray array];
}


#pragma mark - dataSource

- (NSInteger)tableView:(UITableView *)tableView numberOfRowsInSection:(NSInteger)section{
    
    if (self.dataSource == nil) {
        return 0;
    }
    NSLog(@"%luli",(unsigned long)self.dataSource.count);
    
    return self.dataSource.count;
}


- (UITableViewCell *)tableView:(UITableView *)tableView cellForRowAtIndexPath:(NSIndexPath *)indexPath{
    
    UITableViewCell *cell = [tableView dequeueReusableCellWithIdentifier:@"ResultID"];
    
    cell.textLabel.text = [self.dataSource[indexPath.row] objectForKey:@"city"];
    
    return cell;
}

#pragma mark - delegate
- (void)tableView:(UITableView *)tableView didSelectRowAtIndexPath:(NSIndexPath *)indexPath{
    
    [tableView deselectRowAtIndexPath:indexPath animated:NO];
    
    YYLog(@"Select = %@",self.dataSource[indexPath.row])
//    [SQLOperation writeLastCity:self.dataSource[indexPath.row][@"city"]];
    
    if ([self.delegate respondsToSelector:@selector(resultViewController:didSelectFollowCity:)]) {
        [self.delegate resultViewController:self didSelectFollowCity:self.dataSource[indexPath.row][@"city"]];
    }
    
    
    
//    [self dismissViewControllerAnimated:NO completion:nil];
//    [self popRootViewControllerWithName:cityName];
}

//-(NSMutableArray *)dataSource{
//    if(_dataSource == nil){
//        
//        _dataSource = [NSMutableArray array];
//    }
//    return _dataSource;
//}

//- ()

#pragma mark - test


@end
